<?php include_once("header.html"); ?>

<head>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>system/application/styles/admin_view_content.css" />
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<meta name="generator" content="Geany 0.16" />
</head>

<body>
    <div id="space">
	<div id="picture">
		<img src="<?php echo base_url(); ?>system/application/styles/name1.png"></a>
   	</div>
    	<div id="table">

        <?php
            $cols = array();
            $result = mysql_query("SHOW COLUMNS FROM " . $table . "s");
            if (!$result):
                echo mysql_error();
            endif;
                
            //$cols[] = "Zaznacz";
            while ($data = mysql_fetch_array($result)):
                $cols[] = $data["Field"];
            endwhile;
            $dbcolscount = count($cols);
            $cols[] = "Modyfikuj";
            $cols[] = "Usuń";
            
            $this->table->set_heading($cols); 
            
            $row_count = $this->db->count_all($table.'s');
            $items = $this->$table->find_all_by_sql('SELECT * FROM '.$table.'s LIMIT '.($index-10).', 10');
            
            echo form_open('admin/form/add', '', array('table' => $table));
            foreach ($items as $item):
                $row = array();
                for ($i = 0; $i < $dbcolscount; $i++):
                    $row[] = $item->$cols[$i];
                endfor;
                $row[] = anchor('admin/form/modify/'.$table.'/'.$item->id.'/', 'Zmień');
                $row[] = anchor('admin/content/remove/'.$table.'/'.$item->id.'/', 'Usuń');
                $this->table->add_row($row);
            endforeach;
            echo $this->table->generate();
            
            echo form_submit('add', 'Dodaj');
            echo form_close();

            $hidden_prev = array('row_index' => $index, 'shift' => -10, 'table' => $table);
            echo form_open('admin/content/change_page', '', $hidden_prev);
            $tmp = array('name' => 'prev', 'value' => 'Poprzednie 10');
            if ($index == 10):
                $tmp['disabled'] = 'disabled';
            endif;
            echo form_submit($tmp);
            echo form_close();
            
            $hidden_next = array('row_index' => $index, 'shift' => 10, 'table' => $table);
            echo form_open('admin/content/change_page', '', $hidden_next);
            $tmp = array('name' => 'next', 'value' => 'Następne 10');
            if ($row_count <= $index):
                $tmp['disabled'] = 'disabled';
            endif;
            echo form_submit($tmp);
            echo form_close();
           
        ?>
	</div>
</div>
        
      
</body>
